/**
 * @author CH_ywx
 * @Date 2023-06-02
 * @Description
 */
package io.xccit;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

import java.io.InputStream;

/**
 *@author CH_ywx
 *@Date 2023-06-02
 *@Description ehcache测试类
 */
public class EHCacheTest {
    public static void main(String[] args) {
        //获取配置文件
        InputStream inputStream = EHCacheTest.class.getClassLoader().getResourceAsStream("ehcache.xml");
        //创建缓存管理器对象
        CacheManager cacheManager = new CacheManager(inputStream);
        //获取缓存对象(配置文件中的cacheName)
        Cache cache = cacheManager.getCache("HelloWorldCache");
        //创建一个缓存对象
        Element element = new Element("name", "xccit");
        //存进缓存区
        cache.put(element);
        //获取缓存
        Element element1 = cache.get("name");
        System.out.println("缓存的name = " + element1.getObjectValue());
    }
}
